package com.ruoyi.web.controller.biz;

import com.ruoyi.biz.domain.BizCourseExamScore;
import com.ruoyi.biz.service.IBizCourseExamScoreService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程考试题Controller
 *
 * @author fmi110
 * @date 2021-09-02
 */
@Controller
@RequestMapping("/biz/examscore")
public class BizCourseExamScoreController extends BaseController {
    private String prefix = "biz/examscore";

    @Autowired
    private IBizCourseExamScoreService bizCourseExamScoreService;

    @RequiresPermissions("biz:examscore:view")
    @GetMapping()
    public String examscore() {
        return prefix + "/examscore";
    }

    /**
     * 查询课程考试题列表
     */
    @RequiresPermissions("biz:examscore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizCourseExamScore bizCourseExam) {
        startPage();
        Long userId = ShiroUtils.getUserId();
        bizCourseExam.setUserId(userId.intValue());
        List<BizCourseExamScore> list = bizCourseExamScoreService.selectBizCourseExamScoreList(bizCourseExam);
        return getDataTable(list);
    }

    /**
     * 导出课程考试题列表
     */
    @RequiresPermissions("biz:examscore:export")
    @Log(title = "课程考试题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizCourseExamScore bizCourseExam) {
        List<BizCourseExamScore>      list = bizCourseExamScoreService.selectBizCourseExamScoreList(bizCourseExam);
        ExcelUtil<BizCourseExamScore> util = new ExcelUtil<BizCourseExamScore>(BizCourseExamScore.class);
        return util.exportExcel(list, "examscore");
    }

    /**
     * 新增课程考试题
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存课程考试题
     */
    @RequiresPermissions("biz:examscore:add")
    @Log(title = "课程考试题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizCourseExamScore bizCourseExam) {
        return toAjax(bizCourseExamScoreService.insertBizCourseExamScore(bizCourseExam));
    }

    /**
     * 修改课程考试题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizCourseExamScore bizCourseExam = bizCourseExamScoreService.selectBizCourseExamScoreById(id);
        mmap.put("bizCourseExam", bizCourseExam);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程考试题
     */
    @RequiresPermissions("biz:examscore:edit")
    @Log(title = "课程考试题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizCourseExamScore bizCourseExam) {
        return toAjax(bizCourseExamScoreService.updateBizCourseExamScore(bizCourseExam));
    }

    /**
     * 删除课程考试题
     */
    @RequiresPermissions("biz:examscore:remove")
    @Log(title = "课程考试题", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizCourseExamScoreService.deleteBizCourseExamScoreByIds(ids));
    }
}
